/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.client.ZFilterAction;
/*     */ import com.zimbra.client.ZFilterAction.MarkOp;
/*     */ import com.zimbra.client.ZFilterAction.ZDiscardAction;
/*     */ import com.zimbra.client.ZFilterAction.ZFileIntoAction;
/*     */ import com.zimbra.client.ZFilterAction.ZKeepAction;
/*     */ import com.zimbra.client.ZFilterAction.ZMarkAction;
/*     */ import com.zimbra.client.ZFilterAction.ZRedirectAction;
/*     */ import com.zimbra.client.ZFilterAction.ZTagAction;
/*     */ import com.zimbra.client.ZFilterCondition;
/*     */ import com.zimbra.client.ZFilterCondition.HeaderOp;
/*     */ import com.zimbra.client.ZFilterCondition.ZHeaderCondition;
/*     */ import com.zimbra.client.ZFilterRule;
/*     */ import com.zimbra.client.ZFilterRules;
/*     */ import com.zimbra.client.ZFolder;
/*     */ import com.zimbra.client.ZMailbox;
/*     */ import com.zimbra.client.ZMessage;
/*     */ import com.zimbra.client.ZTag;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.Element.XMLElement;
/*     */ import com.zimbra.common.soap.MailConstants;
/*     */ import com.zimbra.common.soap.SoapFaultException;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.filter.RuleManager;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Set;
/*     */ import java.util.TreeSet;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestFilterExisting
/*     */   extends TestCase
/*     */ {
/*     */   private static final String USER_NAME = "user1";
/*     */   private static final String NAME_PREFIX = "TestFilterExisting";
/*     */   private static final String FOLDER1_NAME = "TestFilterExisting-folder1";
/*     */   private static final String FOLDER2_NAME = "TestFilterExisting-folder2";
/*     */   private static final String FOLDER3_NAME = "TestFilterExisting-folder3";
/*     */   private static final String FOLDER1_PATH = "/TestFilterExisting-folder1";
/*     */   private static final String FOLDER2_PATH = "/TestFilterExisting-folder2";
/*     */   private static final String FOLDER3_PATH = "/TestFilterExisting-folder3";
/*     */   private static final String TAG_NAME = "TestFilterExisting-tag";
/*     */   private static final String KEEP_RULE_NAME = "TestFilterExisting keep";
/*     */   private static final String TAG_RULE_NAME = "TestFilterExisting tag";
/*     */   private static final String FLAG_RULE_NAME = "TestFilterExisting flag";
/*     */   private static final String MARK_READ_RULE_NAME = "TestFilterExisting mark read";
/*     */   private static final String FOLDER1_RULE_NAME = "TestFilterExisting folder1";
/*     */   private static final String FOLDER1_AND_FLAG_RULE_NAME = "TestFilterExisting folder1 and flag";
/*     */   private static final String FOLDER2_RULE_NAME = "TestFilterExisting folder2";
/*     */   private static final String FOLDER3_RULE_NAME = "TestFilterExisting folder3";
/*     */   private static final String DISCARD_RULE_NAME = "TestFilterExisting discard";
/*     */   private static final String REDIRECT_RULE_NAME = "TestFilterExisting redirect";
/*     */   private ZFilterRules originalRules;
/*     */   private String originalBatchSize;
/*     */   private String originalSleepInterval;
/*     */   
/*     */   public void setUp()
/*     */     throws Exception
/*     */   {
/*  80 */     cleanUp();
/*     */     
/*  82 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/*  83 */     this.originalRules = mbox.getIncomingFilterRules();
/*  84 */     this.originalBatchSize = TestUtil.getAccountAttr("user1", "zimbraFilterBatchSize");
/*  85 */     this.originalSleepInterval = TestUtil.getAccountAttr("user1", "zimbraFilterSleepInterval");
/*  86 */     saveNewRules();
/*     */     
/*     */ 
/*  89 */     TestUtil.setAccountAttr("user1", "zimbraFilterSleepInterval", "0");
/*     */   }
/*     */   
/*     */ 
/*     */   public void testGetRule()
/*     */     throws Exception
/*     */   {
/*  96 */     String rule1 = "# Rule 1\r\nabc\r\n";
/*  97 */     String rule2 = "# Rule 2\r\ndef\r\n";
/*  98 */     String script = rule1 + rule2;
/*  99 */     assertEquals(rule1, RuleManager.getRuleByName(script, "Rule 1"));
/* 100 */     assertEquals(rule2, RuleManager.getRuleByName(script, "Rule 2"));
/*     */   }
/*     */   
/*     */   public void testKeep() throws Exception {
/* 104 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/* 105 */     String subject = "TestFilterExisting test keep";
/* 106 */     String id = TestUtil.addMessage(mbox, subject);
/* 107 */     String query = "in:inbox subject:\"" + subject + "\"";
/* 108 */     String[] ruleNames = { "TestFilterExisting keep" };
/*     */     
/*     */ 
/* 111 */     Set<String> affectedIds = runRules(ruleNames, id, null);
/* 112 */     assertEquals(0, affectedIds.size());
/* 113 */     TestUtil.getMessage(mbox, query);
/*     */     
/*     */ 
/* 116 */     affectedIds = runRules(ruleNames, null, "in:inbox");
/* 117 */     assertEquals(0, affectedIds.size());
/* 118 */     TestUtil.getMessage(mbox, query);
/*     */     
/*     */ 
/* 121 */     ZFolder folder1 = TestUtil.createFolder(mbox, "/TestFilterExisting-folder1");
/* 122 */     mbox.moveMessage(id, folder1.getId());
/*     */     
/*     */ 
/* 125 */     affectedIds = runRules(ruleNames, id, null);
/* 126 */     assertEquals(0, affectedIds.size());
/* 127 */     query = "in:TestFilterExisting-folder1 subject:\"" + subject + "\"";
/* 128 */     TestUtil.getMessage(mbox, query);
/*     */     
/*     */ 
/* 131 */     affectedIds = runRules(ruleNames, null, "in:TestFilterExisting-folder1");
/* 132 */     assertEquals(0, affectedIds.size());
/* 133 */     TestUtil.getMessage(mbox, query);
/*     */   }
/*     */   
/*     */   public void testFileInto() throws Exception {
/* 137 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/* 138 */     TestUtil.createFolder(mbox, "/TestFilterExisting-folder1");
/* 139 */     TestUtil.createFolder(mbox, "/TestFilterExisting-folder2");
/*     */     
/* 141 */     String subject = "TestFilterExisting test keep, fileinto folder1 and folder2";
/* 142 */     String id = TestUtil.addMessage(mbox, subject);
/* 143 */     String[] ruleNames = { "TestFilterExisting folder1" };
/*     */     
/*     */ 
/* 146 */     Set<String> affectedIds = runRules(ruleNames, id, null);
/* 147 */     assertEquals(1, affectedIds.size());
/* 148 */     assertTrue(affectedIds.contains(id));
/* 149 */     assertMoved("inbox", "TestFilterExisting-folder1", subject);
/*     */     
/*     */ 
/* 152 */     ZMessage msg = TestUtil.getMessage(mbox, "in:TestFilterExisting-folder1 subject:\"" + subject + "\"");
/* 153 */     id = msg.getId();
/* 154 */     ruleNames = new String[] { "TestFilterExisting folder2" };
/* 155 */     affectedIds = runRules(ruleNames, null, "in:TestFilterExisting-folder1");
/* 156 */     assertEquals(1, affectedIds.size());
/* 157 */     assertTrue(affectedIds.contains(id));
/* 158 */     assertMoved("TestFilterExisting-folder1", "TestFilterExisting-folder2", subject);
/*     */     
/*     */ 
/* 161 */     msg = TestUtil.getMessage(mbox, "in:TestFilterExisting-folder2 subject:\"" + subject + "\"");
/* 162 */     id = msg.getId();
/* 163 */     mbox.moveMessage(id, Integer.toString(2));
/*     */     
/*     */ 
/* 166 */     ruleNames = new String[] { "TestFilterExisting keep", "TestFilterExisting folder1", "TestFilterExisting folder2" };
/* 167 */     affectedIds = runRules(ruleNames, id, null);
/* 168 */     assertEquals(1, affectedIds.size());
/* 169 */     assertTrue(affectedIds.contains(id));
/* 170 */     TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
/* 171 */     TestUtil.getMessage(mbox, "in:TestFilterExisting-folder1 subject:\"" + subject + "\"");
/* 172 */     TestUtil.getMessage(mbox, "in:TestFilterExisting-folder2 subject:\"" + subject + "\"");
/*     */   }
/*     */   
/*     */   public void testTag() throws Exception
/*     */   {
/* 177 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/* 178 */     ZTag tag = mbox.createTag("TestFilterExisting-tag", null);
/* 179 */     String subject = "TestFilterExisting test tag";
/* 180 */     String id = TestUtil.addMessage(mbox, subject);
/* 181 */     ZMessage msg = mbox.getMessageById(id);
/*     */     
/*     */ 
/* 184 */     Set<String> affectedIds = runRules(new String[] { "TestFilterExisting flag" }, id, null);
/* 185 */     assertEquals(0, affectedIds.size());
/* 186 */     assertFalse(msg.hasTags());
/*     */     
/*     */ 
/* 189 */     affectedIds = runRules(new String[] { "TestFilterExisting tag" }, id, null);
/* 190 */     assertEquals(1, affectedIds.size());
/* 191 */     assertTrue(affectedIds.contains(id));
/* 192 */     mbox.noOp();
/* 193 */     msg = mbox.getMessageById(id);
/* 194 */     assertEquals(tag.getId(), msg.getTagIds());
/*     */   }
/*     */   
/*     */   public void testFlag() throws Exception
/*     */   {
/* 199 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/* 200 */     String subject = "TestFilterExisting test flag";
/* 201 */     String id = TestUtil.addMessage(mbox, subject);
/* 202 */     ZMessage msg = mbox.getMessageById(id);
/*     */     
/*     */ 
/* 205 */     Set<String> affectedIds = runRules(new String[] { "TestFilterExisting tag" }, id, null);
/* 206 */     assertEquals(0, affectedIds.size());
/* 207 */     assertFalse(msg.isFlagged());
/*     */     
/*     */ 
/* 210 */     affectedIds = runRules(new String[] { "TestFilterExisting flag" }, id, null);
/* 211 */     mbox.noOp();
/* 212 */     msg = mbox.getMessageById(id);
/* 213 */     assertTrue(msg.isFlagged());
/*     */   }
/*     */   
/*     */   public void testMarkRead() throws Exception
/*     */   {
/* 218 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/* 219 */     String subject = "TestFilterExisting test mark read";
/* 220 */     String id = TestUtil.addMessage(mbox, subject);
/* 221 */     mbox.markMessageRead(id, false);
/* 222 */     ZMessage msg = mbox.getMessageById(id);
/* 223 */     assertTrue(msg.isUnread());
/*     */     
/*     */ 
/* 226 */     Set<String> affectedIds = runRules(new String[] { "TestFilterExisting mark read" }, id, null);
/* 227 */     assertEquals(1, affectedIds.size());
/* 228 */     mbox.noOp();
/* 229 */     assertFalse(msg.isUnread());
/*     */   }
/*     */   
/*     */   public void testDiscard() throws Exception
/*     */   {
/* 234 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/* 235 */     String subject = "TestFilterExisting test keep, fileinto folder1, and discard";
/* 236 */     String id = TestUtil.addMessage(mbox, subject);
/*     */     
/*     */ 
/* 239 */     Set<String> affectedIds = runRules(new String[] { "TestFilterExisting keep", "TestFilterExisting discard" }, id, null);
/* 240 */     assertEquals(0, affectedIds.size());
/* 241 */     TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
/*     */     
/*     */ 
/* 244 */     affectedIds = runRules(new String[] { "TestFilterExisting discard", "TestFilterExisting folder1" }, id, null);
/* 245 */     assertMoved("inbox", "TestFilterExisting-folder1", subject);
/*     */     
/*     */ 
/* 248 */     String query = "in:TestFilterExisting-folder1 subject:\"" + subject + "\"";
/* 249 */     ZMessage msg = TestUtil.getMessage(mbox, query);
/* 250 */     affectedIds = runRules(new String[] { "TestFilterExisting discard" }, null, query);
/* 251 */     assertEquals(1, affectedIds.size());
/* 252 */     assertTrue(affectedIds.contains(msg.getId()));
/* 253 */     List<ZMessage> messages = TestUtil.search(mbox, query);
/* 254 */     assertEquals(0, messages.size());
/*     */   }
/*     */   
/*     */   public void testRedirect() throws Exception
/*     */   {
/* 259 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/* 260 */     String subject = "TestFilterExisting test redirect";
/* 261 */     String id = TestUtil.addMessage(mbox, subject);
/* 262 */     String query = "in:inbox subject:\"" + subject + "\"";
/*     */     
/*     */ 
/* 265 */     Set<String> affectedIds = runRules(new String[] { "TestFilterExisting redirect" }, id, null);
/* 266 */     assertEquals(0, affectedIds.size());
/* 267 */     TestUtil.getMessage(mbox, query);
/*     */     
/*     */ 
/*     */ 
/* 271 */     ZMailbox mbox2 = TestUtil.getZMailbox("user2");
/* 272 */     assertEquals(0, TestUtil.search(mbox2, "in: inbox subject:\"" + subject + "\"").size());
/*     */   }
/*     */   
/*     */   private class RunRule implements Runnable
/*     */   {
/*     */     private String mRuleName;
/*     */     private String mIdList;
/*     */     private Exception mError;
/*     */     
/*     */     private RunRule(String ruleName, String idList) {
/* 282 */       this.mRuleName = ruleName;
/* 283 */       this.mIdList = idList;
/*     */     }
/*     */     
/*     */     public void run()
/*     */     {
/*     */       try {
/* 289 */         TestFilterExisting.this.runRules(new String[] { this.mRuleName }, this.mIdList, null);
/*     */       } catch (Exception e) {
/* 291 */         this.mError = e;
/*     */       }
/*     */     }
/*     */     
/*     */     private Exception getError() {
/* 296 */       return this.mError;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public void testSimultaneous()
/*     */     throws Exception
/*     */   {
/* 305 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/* 306 */     List<String> msgIds = new ArrayList();
/* 307 */     for (int i = 1; i <= 10; i++) {
/* 308 */       msgIds.add(TestUtil.addMessage(mbox, "TestFilterExisting discard flag " + i));
/*     */     }
/* 310 */     String idList = StringUtil.join(",", msgIds);
/*     */     
/*     */ 
/* 313 */     RunRule runDiscard = new RunRule("TestFilterExisting discard", idList, null);
/* 314 */     RunRule runFlag = new RunRule("TestFilterExisting flag", idList, null);
/* 315 */     Thread discardThread = new Thread(runDiscard);
/* 316 */     Thread flagThread = new Thread(runFlag);
/* 317 */     discardThread.start();
/* 318 */     flagThread.start();
/* 319 */     discardThread.join();
/* 320 */     flagThread.join();
/*     */     
/*     */ 
/* 323 */     Exception e = runDiscard.getError();
/* 324 */     if (e != null) {
/* 325 */       fail(e.toString());
/*     */     }
/* 327 */     e = runFlag.getError();
/* 328 */     if (e != null) {
/* 329 */       fail(e.toString());
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public void testFileIntoSameFolder()
/*     */     throws Exception
/*     */   {
/* 338 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/* 339 */     ZFolder folder3 = TestUtil.createFolder(mbox, "/TestFilterExisting-folder3");
/* 340 */     String subject = "TestFilterExisting test folder3";
/* 341 */     String id = TestUtil.addMessage(mbox, subject, folder3.getId(), null);
/*     */     
/*     */ 
/* 344 */     Set<String> affectedIds = runRules(new String[] { "TestFilterExisting folder3" }, id, null);
/* 345 */     assertEquals(0, affectedIds.size());
/* 346 */     TestUtil.getMessage(mbox, "subject:\"" + subject + "\"");
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public void testFileIntoSameFolderAndFlag()
/*     */     throws Exception
/*     */   {
/* 354 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/* 355 */     ZFolder folder1 = TestUtil.createFolder(mbox, "/TestFilterExisting-folder1");
/* 356 */     String subject = "TestFilterExisting test folder1 and flag";
/* 357 */     String id = TestUtil.addMessage(mbox, subject, folder1.getId(), null);
/* 358 */     ZMessage msg = mbox.getMessageById(id);
/* 359 */     assertTrue(StringUtil.isNullOrEmpty(msg.getFlags()));
/*     */     
/*     */ 
/* 362 */     Set<String> affectedIds = runRules(new String[] { "TestFilterExisting folder1 and flag" }, id, null);
/* 363 */     assertEquals(1, affectedIds.size());
/* 364 */     msg = TestUtil.getMessage(mbox, "subject:\"" + subject + "\"");
/* 365 */     assertEquals("f", msg.getFlags());
/*     */   }
/*     */   
/*     */ 
/*     */   public void testBatchSize()
/*     */     throws Exception
/*     */   {
/* 372 */     TestUtil.getAccount("user1").setFilterBatchSize(1);
/*     */     
/* 374 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/* 375 */     String subject = "TestFilterExisting testBatchSize flag";
/* 376 */     String msg1Id = TestUtil.addMessage(mbox, subject + " 1");
/* 377 */     String msg2Id = TestUtil.addMessage(mbox, subject + " 2");
/*     */     try {
/* 379 */       runRules(new String[] { "TestFilterExisting flag" }, null, "subject: '" + subject + "'");
/* 380 */       fail("Batch size was not enforced");
/*     */     } catch (SoapFaultException e) {
/* 382 */       String msg = e.getMessage();
/* 383 */       assertTrue(msg.contains("2 messages"));
/* 384 */       assertTrue(msg.contains("limit of 1"));
/*     */     }
/*     */     
/*     */ 
/* 388 */     ZMessage msg = mbox.getMessageById(msg1Id);
/* 389 */     if (msg.hasFlags()) {
/* 390 */       assertFalse(msg.getFlags().contains("f"));
/*     */     }
/* 392 */     msg = mbox.getMessageById(msg2Id);
/* 393 */     if (msg.hasFlags()) {
/* 394 */       assertFalse(msg.getFlags().contains("f"));
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public void testSleepInterval()
/*     */     throws Exception
/*     */   {
/* 403 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/* 404 */     String subject = "TestFilterExisting testSleepInterval";
/* 405 */     TestUtil.addMessage(mbox, subject + " 1");
/* 406 */     TestUtil.addMessage(mbox, subject + " 2");
/*     */     
/* 408 */     TestUtil.getAccount("user1").setFilterSleepInterval("500ms");
/* 409 */     long startTime = System.currentTimeMillis();
/* 410 */     runRules(new String[] { "TestFilterExisting keep" }, null, "subject: '" + subject + "'");
/* 411 */     assertTrue(System.currentTimeMillis() - startTime > 500L);
/*     */   }
/*     */   
/*     */   private void assertMoved(String sourceFolderName, String destFolderName, String subject) throws Exception
/*     */   {
/* 416 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/* 417 */     List<ZMessage> messages = TestUtil.search(mbox, "in:" + sourceFolderName + " subject:\"" + subject + "\"");
/* 418 */     assertEquals(0, messages.size());
/* 419 */     messages = TestUtil.search(mbox, "in:" + destFolderName + " subject:\"" + subject + "\"");
/* 420 */     assertEquals(1, messages.size());
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private Set<String> runRules(String[] ruleNames, String idList, String query)
/*     */     throws Exception
/*     */   {
/* 434 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/*     */     
/*     */ 
/* 437 */     Element request = new Element.XMLElement(MailConstants.APPLY_FILTER_RULES_REQUEST);
/* 438 */     Element rulesEl = request.addElement("filterRules");
/* 439 */     for (String ruleName : ruleNames) {
/* 440 */       rulesEl.addElement("filterRule").addAttribute("name", ruleName);
/*     */     }
/* 442 */     if (idList != null) {
/* 443 */       request.addElement("m").addAttribute("ids", idList);
/*     */     }
/* 445 */     if (query != null) {
/* 446 */       request.addElement("query").setText(query);
/*     */     }
/*     */     
/*     */ 
/* 450 */     Element response = mbox.invoke(request);
/* 451 */     Set<String> affectedIds = new TreeSet();
/* 452 */     Element msgEl = response.getOptionalElement("m");
/* 453 */     if (msgEl != null) {
/* 454 */       for (String id : msgEl.getAttribute("ids").split(",")) {
/* 455 */         affectedIds.add(id);
/*     */       }
/*     */     }
/* 458 */     return affectedIds;
/*     */   }
/*     */   
/*     */   private void saveNewRules() throws Exception {
/* 462 */     List<ZFilterRule> rules = new ArrayList();
/*     */     
/*     */ 
/* 465 */     List<ZFilterCondition> conditions = new ArrayList();
/* 466 */     List<ZFilterAction> actions = new ArrayList();
/* 467 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "tag"));
/* 468 */     actions.add(new ZFilterAction.ZTagAction("TestFilterExisting-tag"));
/* 469 */     rules.add(new ZFilterRule("TestFilterExisting tag", true, false, conditions, actions));
/*     */     
/*     */ 
/* 472 */     conditions = new ArrayList();
/* 473 */     actions = new ArrayList();
/* 474 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "flag"));
/* 475 */     actions.add(new ZFilterAction.ZMarkAction(ZFilterAction.MarkOp.FLAGGED));
/* 476 */     rules.add(new ZFilterRule("TestFilterExisting flag", true, false, conditions, actions));
/*     */     
/*     */ 
/* 479 */     conditions = new ArrayList();
/* 480 */     actions = new ArrayList();
/* 481 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "mark read"));
/* 482 */     actions.add(new ZFilterAction.ZMarkAction(ZFilterAction.MarkOp.READ));
/* 483 */     rules.add(new ZFilterRule("TestFilterExisting mark read", true, false, conditions, actions));
/*     */     
/*     */ 
/* 486 */     conditions = new ArrayList();
/* 487 */     actions = new ArrayList();
/* 488 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "keep"));
/* 489 */     actions.add(new ZFilterAction.ZKeepAction());
/* 490 */     rules.add(new ZFilterRule("TestFilterExisting keep", true, false, conditions, actions));
/*     */     
/*     */ 
/* 493 */     conditions = new ArrayList();
/* 494 */     actions = new ArrayList();
/* 495 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "folder1"));
/* 496 */     actions.add(new ZFilterAction.ZFileIntoAction("/TestFilterExisting-folder1"));
/* 497 */     rules.add(new ZFilterRule("TestFilterExisting folder1", true, false, conditions, actions));
/*     */     
/*     */ 
/* 500 */     conditions = new ArrayList();
/* 501 */     actions = new ArrayList();
/* 502 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "folder1 and flag"));
/* 503 */     actions.add(new ZFilterAction.ZFileIntoAction("/TestFilterExisting-folder1"));
/* 504 */     actions.add(new ZFilterAction.ZMarkAction(ZFilterAction.MarkOp.FLAGGED));
/* 505 */     rules.add(new ZFilterRule("TestFilterExisting folder1 and flag", true, false, conditions, actions));
/*     */     
/*     */ 
/* 508 */     conditions = new ArrayList();
/* 509 */     actions = new ArrayList();
/* 510 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "folder2"));
/* 511 */     actions.add(new ZFilterAction.ZFileIntoAction("/TestFilterExisting-folder2"));
/* 512 */     rules.add(new ZFilterRule("TestFilterExisting folder2", true, false, conditions, actions));
/*     */     
/*     */ 
/*     */ 
/* 516 */     conditions = new ArrayList();
/* 517 */     actions = new ArrayList();
/* 518 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "folder3"));
/* 519 */     actions.add(new ZFilterAction.ZFileIntoAction("TestFilterExisting-folder3"));
/* 520 */     rules.add(new ZFilterRule("TestFilterExisting folder3", true, false, conditions, actions));
/*     */     
/*     */ 
/* 523 */     conditions = new ArrayList();
/* 524 */     actions = new ArrayList();
/* 525 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "discard"));
/* 526 */     actions.add(new ZFilterAction.ZDiscardAction());
/* 527 */     rules.add(new ZFilterRule("TestFilterExisting discard", true, false, conditions, actions));
/*     */     
/*     */ 
/*     */ 
/* 531 */     conditions = new ArrayList();
/* 532 */     actions = new ArrayList();
/* 533 */     conditions.add(new ZFilterCondition.ZHeaderCondition("subject", ZFilterCondition.HeaderOp.CONTAINS, "redirect"));
/* 534 */     actions.add(new ZFilterAction.ZRedirectAction(TestUtil.getAddress("user2")));
/* 535 */     rules.add(new ZFilterRule("TestFilterExisting redirect", true, false, conditions, actions));
/*     */     
/*     */ 
/* 538 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/* 539 */     mbox.saveIncomingFilterRules(new ZFilterRules(rules));
/*     */   }
/*     */   
/*     */   protected void tearDown() throws Exception
/*     */   {
/* 544 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/* 545 */     mbox.saveIncomingFilterRules(this.originalRules);
/* 546 */     TestUtil.setAccountAttr("user1", "zimbraFilterBatchSize", this.originalBatchSize);
/* 547 */     TestUtil.setAccountAttr("user1", "zimbraFilterSleepInterval", this.originalSleepInterval);
/* 548 */     cleanUp();
/*     */   }
/*     */   
/*     */   private void cleanUp() throws Exception {
/* 552 */     TestUtil.deleteTestData("user1", "TestFilterExisting");
/*     */   }
/*     */   
/*     */   public static void main(String[] args) throws Exception {
/* 556 */     TestUtil.cliSetup();
/* 557 */     TestUtil.runTest(TestFilterExisting.class);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestFilterExisting.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */